#import "NSAttributedString+Category.h"
@implementation NSAttributedString (Category)
/// 返回label高度
- (CGFloat)getLabelHeightWithWidth:(CGFloat)width
{
    return [self boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading context:nil].size.height;
}

/// 返回label高度，最小高度为minLabelheight
- (CGFloat)getLabelHeightWithMinLabelHeight:(CGFloat)minLabelheight Width:(CGFloat)width
{
    return MAX(minLabelheight, [self getLabelHeightWithWidth:width]);
}

/// 返回label对比minLabelheight增加高度（大于0）
- (CGFloat)getGainedLabelHeightWithMinLabelHeight:(CGFloat)minLabelheight Width:(CGFloat)width
{
    CGFloat divHeight = [self getLabelHeightWithMinLabelHeight:minLabelheight Width:width] - minLabelheight;
    
    return  0 < divHeight ? divHeight : 0;
}

/// 返回cell的高度,minLabelheight为label的最小高度，minCellheight为cell的最小高度
- (CGFloat)getCellHeightWithMinCellHeight:(CGFloat)minCellheight MinLabelHeight:(CGFloat)minLabelheight Width:(CGFloat)width
{
    
    return minCellheight + [self getGainedLabelHeightWithMinLabelHeight:minLabelheight Width:width];
}


+ (NSMutableAttributedString *)getAttributedTextWithLeftNormalText:(NSString *)leftText middle:(NSString *)middleText rightNormalText:(NSString *)rightText normalTextColor:(UIColor *)normalTextColor normalFont:(UIFont *)normalFont middleTextColor:(UIColor *)middleTextColor middleFont:(UIFont *)middleFont
{
    if (leftText.length == 0)
    {
        leftText = @"";
    }
    if (middleText.length == 0)
    {
        middleText = @"";
    }
    if (rightText.length == 0)
    {
        rightText = @"";
    }

    NSString * text = [NSString stringWithFormat:@"%@%@%@",leftText,middleText,rightText];
    
    NSMutableAttributedString * attributedText = [[NSMutableAttributedString alloc] initWithString:text];
    NSDictionary * attrsDictionary = @{NSFontAttributeName:normalFont,NSForegroundColorAttributeName:normalTextColor};
    NSDictionary * attrsDictionary2 = @{NSFontAttributeName:middleFont,NSForegroundColorAttributeName:middleTextColor};
    
    if (leftText.length)
    {
        [attributedText addAttributes:attrsDictionary range:NSMakeRange(0 , leftText.length)];
    }
    if (middleText.length)
    {
        [attributedText addAttributes:attrsDictionary2 range:NSMakeRange(leftText.length,middleText.length)];
    }
    if (rightText.length)
    {
        [attributedText addAttributes:attrsDictionary range:NSMakeRange(leftText.length+middleText.length,rightText.length)];
    }
    
    return attributedText;
}

@end
